<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::post('login/', 'API\PassportController@login');
Route::post('register/', 'API\PassportController@register');
Route::get('wx/', 'API\APIController@index');
Route::post('wx/', 'API\APIController@store');
Route::get('image/', function (){

    $url = Storage::url('app/public/img/logo.png');
//    return __DIR__.'/..'.$url;
    return response()->download(realpath(base_path('public/img')).'/logo.png',
        'Laraveldown.png');
    //return $url;
});






Route::group(['middleware' => 'auth:api'], function () {
    Route::get('logout/', 'API\PassportController@logout');
/*    Route::get('/firstlevel', 'Title\AddFirstTitleController@getAll');
    Route::post('/firstlevel', 'Title\AddFirstTitleController@store');
    Route::get('/firstlevel/{id}', 'Title\AddFirstTitleController@show');
    Route::put('/firstlevel/{id}', 'Title\AddFirstTitleController@update');
    Route::delete('/firstlevel/{id}', 'Title\AddFirstTitleController@destroy');*/
    Route::apiResource('firstlevel', 'Title\AddFirstTitleController');
    Route::apiResource('secondlevel', 'Title\AddSecondTitleController');
    Route::apiResource('MealSupplementBalance', 'Order\MealSupplementBalanceController')->only([
        'index', 'update'
    ]);
    Route::apiResource('order', 'Order\UserOrderController');
    Route::get('/level', 'Title\AddFirstTitleController@getLevel');
    Route::apiResource('user', 'User\UserController');
    Route::post('/changePassword', 'User\UserController@changePassword');
    Route::apiResource('group', 'User\AuthGroupController');
    Route::apiResource('usergroup', 'User\AuthUserGroupsController');
});

/*Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});*/

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('/menu', 'API\MenuController@index');
    Route::post('/menu', 'API\MenuController@store');
    Route::delete('/menu', 'API\MenuController@destroy');
});

Route::get('order_price', function (){
    $new_order_price['message'] = '收钱成功';
    $new_order_price['created_at'] = date('Y-m-d H:i:s');
    $new_order_price['status'] = 200;
    event(new App\Events\OrderPriceNotice($new_order_price));
    return Response::make(['haha']);
});

/*Route::get('/redirect', function () {
    $query = http_build_query([
        'client_id' => '4',
        'redirect_uri' => 'http://127.0.0.1:8000/auth/callback',
        'response_type' => 'code',
        'scope' => '',
    ]);

    return redirect('http://127.0.0.1:8000/oauth/authorize?' . $query);
});*/

/*Route::get('/auth/password', function (\Illuminate\Http\Request $request) {
    $http = new \GuzzleHttp\Client();

    $response = $http->post('http://127.0.0.1/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => '5',
            'client_secret' => 'pdtlbC065k6JMC4dbQUi0wfMKIl1A4iO3PkGXGD8',
            'username' => '1270705632@qq.com',
            'password' => 'Ye@15629598377',
            'scope' => '',
        ],
    ]);

    return json_decode((string)$response->getBody(), true);
});*/
